﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YogaDictionary.Model;

namespace YogaDictionary.Common
{
    public static class Extentions
    {
        public static bool IsNullOrEmpty(this string str)
        {
            return string.IsNullOrEmpty(str);
        }

        public static bool IsNullOrEmpty<T>(this IEnumerable<T> enumerable)
        {
            if (enumerable == null)
                return true;
            return !enumerable.Any();
        }

        public static string ConcatToStringWithSeparator(this List<Word> list, string separator)
        {
            if (list.IsNullOrEmpty())
                return default(string);
            var concat = "";
            if (list.Count() >= 2)
                concat = list.GetRange(0, list.Count - 2).Aggregate("", (str, v) => str + v.Value + ", ");
            return concat + list.Last().Value;
        }


        /*
        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            if (source == null)
                throw new ArgumentNullException("source");
            if (action == null)
                throw new ArgumentNullException("action");

            var copyOfSource = source.ToList();
            for (int i = 0; i < copyOfSource.Count(); i++)
                action(copyOfSource[i]);
        }
        */

    }
}
